"""
发起接口请求必备要素：
请求方式、请求参数（body、headers）、请求地址、端口号

做接口测试关注：
response体、status code
"""
import requests

# 发起请求 post

response = requests.post(url = "http://8.140.193.160:8899/adminapi/login",json = {"account":"admin","pwd":"920509","imgcode":"a"})

# 接受响应
# print(response.json())

# 取出token
token = response.json()['data']['token']

#取出/admin/home/
# print(response.json()['data']['menus'][0]['path'])

# 打印接口的状态码
# print(response.status_code)


# 发起请求  get
base_url = "http://8.140.193.160:8899"

# 因为get请求可以将参数拼接在url的后面，所以可以这样写
response1 = requests.get\
    (base_url + "/adminapi/user/user_group/list?page=1&limit=15",
     headers={"Authori-zation":"Bearer "+str(token)})

# print(response1.json())

# 也可以将get请求的参数写在params里面
response2 = requests.get(base_url + "/adminapi/user/user_group/list",
             params={"page":1,"limit":15},
             headers={"Authori-zation":"Bearer "+str(token)}
             )

# print(response2.json()) # 返回的内容为python的原始对象：字典

# 获取URL
# print(response2.url)

# 获取cookie
# print(response2.cookies)

# 获取响应头
# print(response2.headers)

# 获取响应时间
# print(response2.elapsed.microseconds)

# 获取文本格式
# print(response2.text)

# 返回二进制
# print(response2.content)

# requests 上传图片
#  https://graph.baidu.com/upload
url = "https://graph.baidu.com/upload"
files = {
    "image":("333.jpg",open('C:\\Users\\Administrator\\Desktop\\333.jpg','rb'),"image/jpeg"),
}
r = requests.post(url,files=files)
print(r.json())






